<!DOCTYPE html>

<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Edit Storage</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script type="text/javascript" th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item" style="display: none">
                <label for="storageNo" class="layui-form-label">
                    <span class="x-red">*</span>仓库编号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="storageNo" name="storageNo"
                           required="" lay-verify="storageNo" autocomplete="off"
                           class="layui-input" th:value="${storage.storageNo}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="storageName" class="layui-form-label">
                    <span class="x-red">*</span>仓库名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="storageName" name="storageName" required=""
                           lay-verify="storageName" autocomplete="off" class="layui-input" th:value="${storage.storageName}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的仓库名
                </div>
            </div>

            <div class="layui-form-item">
                <label for="storageAddress" class="layui-form-label">仓库地址</label>
                <div class="layui-input-inline">
                    <input type="text" id="storageAddress" name="storageAddress"
                           required="" lay-verify="storageAddress" autocomplete="off"
                           class="layui-input" th:value="${storage.storageAddress}">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="capacity" class="layui-form-label">
                    <span class="x-red">*</span>仓库容量
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="capacity" name="capacity"
                           required="" lay-verify="capacity" autocomplete="off"
                           class="layui-input" th:value="${storage.capacity}">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="warnLine" class="layui-form-label">
                    <span class="x-red">*</span>仓库报警线
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="warnLine" name="warnLine"
                           required="" lay-verify="warnLine" autocomplete="off"
                           class="layui-input" th:value="${storage.warnLine}">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="standingStock" class="layui-form-label">
                    <span class="x-red">*</span>仓库现存量
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="standingStock" name="standingStock"
                           required="" lay-verify="standingStock" autocomplete="off"
                           class="layui-input" th:value="${storage.standingStock}">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button id="L_repass" class="layui-btn" lay-filter="edit" lay-submit="">修改</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use([ 'form', 'layer', 'jquery','upload' ],
        function() {
            $ = layui.jquery;
            const form = layui.form, layer = layui.layer;

            //自定义验证规则
            form
                .verify({
                    userName : function(value) {
                        if (value.length < 5) {
                            return '昵称至少得5个字符啊';
                        }
                    },
                    capacity : function (value) {
                        if(/^\d+$/.test(value) === false && /^\d+\.\d+$/.test(value) === false)
                        {
                            return '你输入的不是数字';
                        }
                    },
                    warnLine : function (value) {
                        if(/^\d+$/.test(value) === false && /^\d+\.\d+$/.test(value) === false)
                        {
                            return '你输入的不是数字';
                        }
                    },
                    standingStock : function (value) {
                        if(/^\d+$/.test(value) === false && /^\d+\.\d+$/.test(value) === false)
                        {
                            return '你输入的不是数字';
                        }
                    }
                });

            //监听提交
            form.on('submit(edit)', function(data) {
                console.log(data.field)
                $.ajax({
                    url : "/storage/edit",
                    method : 'post',
                    data : data.field,
                    dataType : 'JSON',
                    success : function(res) {
                        if (res.code === 0) {
                            //弹出提示，并在1秒后进行跳转
                            layer.alert("修改成功", {
                                icon : 6
                            }, function() {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                                return false;
                            });
                        } else {
                            layer.msg("修改失败:" + res.msg);
                            return false;
                        }
                    }
                });
                return false;
            });
        })
</script>
</body>
</html>

